//
//  TimClassMap.swift
//  TimMusic
//
//  Created by nkl on 2024/10/23.
//
/// 根据名字维护的映射表
import Foundation
import SwiftUI

struct TimClassMap {
    static var isRunningInWidget: Bool {
        let bundleIdentifier = Bundle.main.bundleIdentifier
        return bundleIdentifier?.contains("widget") ?? false
    }

    static func map(name: String, isStatic: Bool = false) -> any View {
        let sharedDefaults = UserDefaults(suiteName: TimeGroupName)
        let title = sharedDefaults?.string(forKey: "widgetTitle") ?? "Unknown"
        let imageData = sharedDefaults?.data(forKey: "widgetImageData")
        let auth = sharedDefaults?.string(forKey: "widgetDetail") ?? "Unknown"
        let isPlay = sharedDefaults?.bool(forKey: "widgetPlay") ?? false

        let model: ControlMusicModel
        if isStatic {
            model = ControlMusicModel(title: "Lover", auth: "Taylor Swift", imageData: nil, isPlay: isPlay, isStatic: isStatic)
        } else {
            model = ControlMusicModel(title: title, auth: auth, imageData: imageData, isPlay: isPlay, isStatic: isStatic)
        }
        switch name {
        case "Small_MusicCD01_01":
            return Small_MusicCD01_01(model: model)
        case "Small_MusicCD01_02":
            return Small_MusicCD01_02(model: model)
        case "Medium_MusicCD01_01":
            return Medium_MusicCD01_01(model: model)

        case "Small_MusicCD02_01":
            return Small_MusicCD02_01(model: model)
        case "Small_MusicCD02_02":
            return Small_MusicCD02_02(model: model)
        case "Medium_MusicCD02_01":
            return Medium_MusicCD02_01(model: model)

        case "Small_MusicCD03_01":
            return Small_MusicCD03_01(model: model)
        case "Small_MusicCD03_02":
            return Small_MusicCD03_02(model: model)
        case "Medium_MusicCD03_01":
            return Medium_MusicCD03_01(model: model)
            
        case "Medium_MusicCD04_01":
            return Medium_MusicCD04_01(model: model)

        /// standby
        case "Small_StandbyRight_01":
            return Small_StandbyRight_01()
        case "Small_StandbyLeft_01":
            return Small_StandbyLeft_01(model: model)
        case "Medium_StandbyMedium_01":
            return Medium_StandbyMedium_01(model: model)

        case "Small_StandbyRight_02":
            return Small_StandbyRight_02()
        case "Small_StandbyLeft_02":
            return Small_StandbyLeft_02(model: model)
        case "Medium_StandbyMedium_02":
            return Medium_StandbyMedium_02(model: model)

        case "Small_StandbyRight_03":
            return Small_StandbyRight_03(model: model)
        case "Small_StandbyLeft_03":
            return Small_StandbyLeft_03(model: model)
        case "Medium_StandbyMedium_03":
            return Medium_StandbyMedium_03(model: model)

        case "Small_StandbyRight_04":
            return Small_StandbyRight_04(model: model)
        case "Small_StandbyLeft_04":
            return Small_StandbyLeft_03(model: model)
        case "Medium_StandbyMedium_04":
            return Medium_StandbyMedium_04(model: model)

        default:
            return Small_MusicCD01_01(model: .init(title: "", auth: "", imageData: nil, isPlay: false, isStatic: isStatic))
        }
    }
}
